//
//  UIListItem.h
//  storm
//
//  Created by wangdi on 13-8-18.
//
//

#ifndef __storm__UIListItem__
#define __storm__UIListItem__

#include "UIPanel.h"

namespace storm
{
    class UIList;
    class UIListItem : public UIPanel
    {
    public:
        enum ItemType
        {
            TYPE_SCALE,
            TYPE_CHANGE
        };
        
    public:
        sigslot::signal1<UIListItem *> OnSelected;
    public:
        
        static UIListItem *Create(bool bHor, bool bUseFrame = false, const char *szBack = NULL);
    public:
        virtual UIWidget *onReceiveNewTouch(cocos2d::CCTouch *pTouch) ;
        virtual void onCurTouchMoving(cocos2d::CCTouch *pTouch);
        virtual void onCurTouchFinish(cocos2d::CCTouch *pTouch);
        
    public:
        
        void SetChangeType(ItemType type);
        void SetChangeItem(bool bHor, bool bUseFrame = false, const char *szBack = NULL);
        void Active(bool bActive);
        
        void  SetParentList(UIList *pList) {m_pParentList = pList;}
        void  SetSize(float size) {m_size = size;}
        float GetSize() const     {return m_size;}
        cocos2d::CCSprite *NormalBackSprite() {return m_pSprBack;}
        cocos2d::CCSprite *ChangeBackSprite() {return m_pSprChange;}
        
        void AddControlToNormal(UIWidget *pNewControl, cocos2d::CCPoint ptPos, int zOrder);
        void AddControlToChange(UIWidget *pNewControl, cocos2d::CCPoint ptPos, int zOrder);
        
    private:
        CREATE_FUNC(UIListItem);
        UIListItem()
        : m_pSprBack(NULL)
        , m_bActive(false)
        , m_pSprChange(NULL)
        {
        }
        void InitState(bool bHor, const char *szBack, bool bUseFrame);
    private:
        UIList *m_pParentList;
        ItemType    m_type;
        float       m_size;
        bool        m_bActive;
        
        cocos2d::CCSprite *m_pSprBack;
        cocos2d::CCSprite *m_pSprChange;
        WidgetList        m_listControlNormal;
        WidgetList        m_listControlChange;
    };
}

#endif /* defined(__storm__UIListItem__) */
